package com.zhangxin.aiInterview.manager.wsserver;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * WebSocket配置
 * 配置WebSocket处理器和拦截器
 */
@Configuration
@EnableWebSocket
public class WsConfig implements WebSocketConfigurer {

    //消息处理器
    @Resource
    private WsMessageHandler wsMessageHandler;
    //拦截器
    @Resource
    private WsHandshakeInterceptor wsHandshakeInterceptor;


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 给websocket配置访问路径，配置处理器和拦截器
        registry.addHandler(wsMessageHandler, "/ws/audio/interview")
                //添加拦截器
                .addInterceptors(wsHandshakeInterceptor)
                //允许跨域连接websocket
                .setAllowedOrigins("*");
    }
}

